﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;

namespace SZ
{
    public partial class InputeControlPoints : Form
    {
        public InputeControlPoints()
        {
            InitializeComponent();
        }

        private void ImportBtn_Click(object sender, EventArgs e)
        {
            IWorkspace pWorkspace;
            ConnectSDE connectSDE = new ConnectSDE();
            pWorkspace = connectSDE.SdeWorkspace();

            //查找SZDB数据集和Controls要素类
            IEnumDatasetName pEnumDatasetName;
            pEnumDatasetName = pWorkspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);

            IDatasetName pDatasetName;
            pEnumDatasetName.Reset();
            pDatasetName = pEnumDatasetName.Next();
            while (pDatasetName != null)
            {
                if (pDatasetName.Name == "SDE.SZXM")
                {
                    IFeatureWorkspace pFeatureWorkspace;
                    pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
                    IFeatureDataset pFeatureDataset;
                    pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDatasetName.Name);
                    IEnumDataset pSubEnumDataset;
                    pSubEnumDataset = pFeatureDataset.Subsets;
                    IDataset pSubDataset;
                    pSubEnumDataset.Reset();
                    pSubDataset = pSubEnumDataset.Next();
                    while (pSubDataset.Name != null)
                    {
                        if (pSubDataset.Name == "SDE.ControlPoints")
                        {

                            IFeatureClass pFeatureClass;
                            pFeatureClass = pSubDataset as IFeatureClass;

                            ITable pTable = pFeatureClass as ITable;
                            IRow pRow;
                            pRow = pTable.CreateRow();
                            pRow.set_Value(1, textEdit1.Text);
                            pRow.set_Value(2, Convert.ToDouble(textEdit2.Text));
                            pRow.set_Value(3, Convert.ToDouble(textEdit3.Text));
                            pRow.set_Value(4, Convert.ToDouble(textEdit4.Text));
                            pRow.set_Value(5, Convert.ToDouble(textEdit5.Text));
                            pRow.set_Value(6, Convert.ToDouble(textEdit6.Text));
                            pRow.set_Value(7, Convert.ToDouble(textEdit7.Text));
                            pRow.set_Value(8, comboBoxEdit1.Text);

                            IPoint pPoint = new PointClass();
                            pPoint.PutCoords(Convert.ToDouble(textEdit2.Text), Convert.ToDouble(textEdit3.Text));
                            pRow.set_Value(9, pPoint);
                            pRow.Store();
                            MessageBox.Show("输入成功！");

                            textEdit1.Text = "";
                            textEdit2.Text = "";
                            textEdit3.Text = "";
                            textEdit4.Text = "";
                            textEdit5.Text = "";
                            textEdit6.Text = "";
                            textEdit7.Text = "";
                            comboBoxEdit1.Text = "";

                            this.richTextBox1.AppendText(textEdit1.Text);
                            return;

                        }
                        pSubDataset = pSubEnumDataset.Next();
                    }


                }
                pDatasetName = pEnumDatasetName.Next();

            }
        }

        private void CancelBtn_Click(object sender, EventArgs e)
        {
            textEdit1.Text = "";
            textEdit2.Text = "";
            textEdit3.Text = "";
            textEdit4.Text = "";
            textEdit5.Text = "";
            textEdit6.Text = "";
            textEdit7.Text = "";
            comboBoxEdit1.Text = "";
            this.Close();
        }

        private void previewBtn_Click(object sender, EventArgs e)
        {
            this.Owner.WindowState = FormWindowState.Normal;
            this.WindowState = FormWindowState.Minimized;
        }
    }
}
